package com.chat.db.nosql.redis;

import com.chat.db.SessionFactory;
import com.chat.db.SessionFactoryPool;
import com.chat.db.nosql.NoSqlConfiguration;

public class RedisConfiguration extends NoSqlConfiguration {
    protected RedisConfiguration(String dbHost, int dbPort, String dbDriverName) {
        this(dbHost, dbPort + "", dbDriverName, true, null);
    }

    public RedisConfiguration(String dbHost, String clusters, String dbDriverName, boolean isSingle, String password) {
        // TODO 检测参数
        super(dbHost, clusters, dbDriverName, isSingle);
        dbConfig.setPassword(password);
    }

    @Override
    public SessionFactory buildSessionFactory() {
        super.buildSessionFactory();

        if (SessionFactoryPool.getInstance().isExist(getKey())) return SessionFactoryPool.getInstance().get(getKey());

        SessionFactory factory = new RedisSessionFactory(this);
        return SessionFactoryPool.getInstance().put(getKey(), factory);
    }
}
